package org.example.sec11.interceptors.client;

import io.grpc.*;

import java.util.Objects;

public class GzipInterceptor implements ClientInterceptor {
    private final String name;

    public GzipInterceptor(String name) {
        this.name = name;
    }

    @Override
    public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel channel) {
        if (Objects.isNull(callOptions.getCompressor())) {
            callOptions = callOptions.withCompression(name);
        }
        return channel.newCall(method, callOptions);
    }
}
